{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Probability concepts\n",
    "\n",
    "In this notebook we will go over some essential concepts in probability, such as **events, random variables, probability and probability distribution**. They seem simple but also sometimes are quite confusing to someone new to probability.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Sample space, outcomes, events\n",
    "There are things in lif that are a bit *random* in the sense that we do not know the outcome with certainty before it occurs, so we reason about the uncertainties with tools of probability. \n",
    "\n",
    "For an experiment with uncertain outcomes, we denote all possible outcomes as a *set* $S$, and call it the *sample space*. The actual outcome(s) will belong to this set.\n",
    "\n",
    "An *event* $E$ is a subset of $S$ (i.e. $E \\subseteq S$) and we would say event $E$ *occurred* if the actual outcome(s) belongs to $E$ (i.e. $s_{actual} \\in E$).\n",
    "\n",
    "To make this concrete, let's look at a single roll if a 6-sided dice.\n",
    "\n",
    "The sample space $S$ in this case is a set of 6 elements: $S=\\{\\text{Face 1 shows up}, \\text{Face 2 shows up}, \\dots, \\text{Face 6 shows up}\\}$\n",
    "\n",
    "We could define an event however we want. For exampple we can define event $E_1$ to be the event face 5 shows up, define an event $E_2$ to be the event \"a face with even number shows up\", and define an event $E_3$ to be the event \"the face shows up is not 2 or 3\". They are expressed as follows:\n",
    "\n",
    "$$E_1 =\\{\\text{Face 5 shows up}\\}$$\n",
    "$$E_2 =\\{\\text{Face 2 shows up},\\text{Face 4 shows up},\\text{Face 6 shows up}\\}$$\n",
    "$$E_3^c =\\{\\text{Face 2 shows up}, \\text{Face 3 shows up}\\}, E_3=S-E_3^c$$\n",
    "\n",
    "In the above, we introduced the notation $^c$ to mean the complementation of a set. Specifically, it means $E_3^c$ occurs if and only if $E_3$ does not occur. \n",
    "\n",
    "A few other notations on set algebra might be helpful to review: https://en.wikipedia.org/wiki/Algebra_of_sets"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Probability\n",
    "\n",
    "\"Probability is the measure of the likelihood that an event will occur. Probability is quantified as a number between 0 and 1, where, loosely speaking, 0 indicates impossibility and 1 indicates certainty.\" - Wikipedia\n",
    "\n",
    "We can interpret probability as the frequency of certain event occur if we do the experiment many many times. This long-run frequency view is the *frequentist* view. Or we can interpret probability as our degree of belief in the event, which is useful for experiments that are not possible to repeat over and over. This is the *Bayesian* view.\n",
    "\n",
    "We use $P(A)$ to denote the probabily that event $A$ occurs and define probability with the following axioms:\n",
    "- $P(S)=1$, $P(\\emptyset)=0$\n",
    "- Disjoint/mutually exclusive events, $A_1, A_2, \\dots$ are defined such that $A_i \\cap A_j = \\emptyset$ for $i\\neq j$. And we have \n",
    "$$P \\left( \\bigcup_{i=1}^{\\infty}A_i \\right) = \\sum_{i=1}^{\\infty}P(A_i) $$\n",
    "\n",
    "\n",
    "Following the definiiton we have properties:\n",
    "- $P(A) + P(A^c)=1$\n",
    "- $A \\subseteq B \\Rightarrow P(A) \\leq P(B)$\n",
    "- $P(A \\cup B) = P(A) + P(B) - P(A \\cap B)$\n",
    "\n",
    "The last property can be generalized into the [inclusion-exclusion theorem](https://en.wikipedia.org/wiki/Inclusion%E2%80%93exclusion_principle) for more than two sets."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's try to find the probability of $E_1$, $E_2$ and $E_3$ in our dice example. Assume our dice is fair, meaning each face will show up equally likely. Denote $A_i$ to be the outcome face $i$ shows up, we have $ \\sum_{i=1}^6 A_i = 1 $ and $A_1=A_2= \\dots = A_6$, therefore $A_i=\\frac{1}{6}$. \n",
    "\n",
    "The fairness of the dices gives the problem **symmetry** (i.e. all $A_i$s are equal). In addition $A_i$s are **mutually exclusive** (a roll of a single dice cannot possibly take more than one value). Therefore we can resort to counting the **number of occurences** for calculating probability:\n",
    "\n",
    "$$P(E) = \\frac{\\text{number of outcomes in E}}{\\text{number of all possible outcomes}}$$\n",
    "\n",
    "Thus we have $P(E_1)=\\frac{1}{6}$, $P(E_2)=\\frac{3}{6}=\\frac{1}{2}$ and $P(E_3)=\\frac{4}{6}=\\frac{2}{3}$\n",
    "\n",
    "The assumption/condition that **all the outcomes are equally likely and mutually exclussive** forms the basis for couting and combinatorics that we will go over in the next section."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Random variable\n",
    "\n",
    "In the discussion above, we have $P(\\cdot)$ notation for probability, it is a function that takes an event as input and outputs a real value that is between 0 and 1.\n",
    "\n",
    "In order to fully utilize the tools we have in calculus, it would be nice to have the input of $P(\\cdot)$ be real valued. And random variable comes to resume.\n",
    "\n",
    "**A random variable maps sample space $S$ to real numbers $\\mathbb{R}$.** That's it. The exact mapping is up to use to define. \n",
    "\n",
    "![rv.png](rv.png)\n",
    "(Image credit: *Blitzstein, Joseph K., and Jessica Hwang. Introduction to probability. CRC Press, 2014.*)\n",
    "\n",
    "For example, we could define a random variable $X$ (we usually use capital letter to denote a random variable) to take on value $i$ if the dice face $i$ shows up.\n",
    "\n",
    "For example, if we roll the dice twice, we could define a random variable $Y$ to take on the value $i_1+i_2$, where $i_1$ and $i_2$ are the dice value of the first and second roll respectively. Thus very conveniently $Y=7$ represents the outcomes of $(i_1, i_2)$ takes on values of $\\{(1,6), (6,1), (2, 5), (5, 2), (3,4), (4,3) \\})$ from the two rolls. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Probability distribution\n",
    "\n",
    "Now that we have both the input and output of $P(\\cdot)$ as real numbers, it is natual to think of $P(\\cdot)$ as function that describes the probability of random variable taking of various values. More concretely $P(X=k)=P(k)=f_X(k)$.\n",
    "\n",
    "For our dice example above, because $X$ and $Y$ takes on discrete values, they are called discrete random variables. Their $P(\\cdot)$ functions are called probability mass functions (PMF). Because at each of the value $k$ the variable takes, P(k) is indeed a probability. This is in contrast to the continuous version of the random variables. \n",
    "\n",
    "For continuous random variables, the probability of taking on an exact real number is zero, and it is more useful to talk about the probabiliy for taking on values of certain interval, so the equivalent of $P(\\cdot)$ there is called probability density function (PDF).\n",
    "\n",
    "To get some feeling about PMF, let's calculate the PMF for $Y$. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "from collections import defaultdict\n",
    "%matplotlib inline\n",
    "\n",
    "p_y = defaultdict(int)\n",
    "for i in range(1, 7):\n",
    "    for j in range(1, 7):\n",
    "        s = i+j\n",
    "        p_y[s] +=1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "defaultdict(int,\n",
       "            {2: 1,\n",
       "             3: 2,\n",
       "             4: 3,\n",
       "             5: 4,\n",
       "             6: 5,\n",
       "             7: 6,\n",
       "             8: 5,\n",
       "             9: 4,\n",
       "             10: 3,\n",
       "             11: 2,\n",
       "             12: 1})"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p_y"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can see that $Y$ only takes on certain values (2 to 12), this set of values are called the *support*, outside of the support $P(Y)=0$. To get the probability, we should divide the count outcomes by the total count of all possible outcomes."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.text.Text at 0x1134422b0>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYQAAAEICAYAAABfz4NwAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAGhZJREFUeJzt3X90XOV95/H3J/KPKFCiAE4XyyY4i1fEga1dhAPbLd0N\nJTJtgnWyJrEPDWaXs2Zz6t3sZiti7yak9aZNWHVLm1OaxA2/A7apY4ySmlVpKN2TXX5YYNbCUIFw\niC3JKSIgQhMF2/J3/5hH7DCM0R1pRmPNfF7nzNG9z33uc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f5U2K8Al0t6AdgKfFjSt6rbpYobAAYiYvzIbzu5gKhlvw78ICKG\nI+IIsAP4Z1Xu03T5e0lnAKSfL1a5P9NC0lrgo8CVUaE3kNV8IEgSuXPLz0TEH1W7P5UWERsjYkFE\nnEXuIuODEVHT/zlGxI+Ag5JaUtEl5L7Hu5YdAC6U9K70HL+EGr+QnqcLWJum1wL3VbEv00LSCuBz\nwOUR8bNKbafmA4Hcf8yfIvef8pPp8RvV7pSV3b8H7pK0F1gK/EGV+1NR6WhoO/AE0EvutVxzH+cg\naQvwMNAiaUDSNcBXgEslPQdcmuZrxnHG/KfALwAPpH3Y1yuybX90hZmZQX0cIZiZWQYOBDMzAxwI\nZmaWOBDMzAxwIJiZWeJAMDMzwIFgZmbJ/wM2o9sA5317XwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1100d4908>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "x,y =zip(*[(k, v/36) for k,v in p_y.items()])\n",
    "plt.stem(x,y)\n",
    "plt.title('PMF of Y')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  },
  "widgets": {
   "state": {},
   "version": "1.1.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
